package LC;

/**
 * @ClassName LC38
 * @Description: TODO
 * @Author hl
 * @Date 2021/4/20
 * @Version V1.0
 **/
public class LC38 {
    public static String countAndSay(int n) {
        String s = "1";
        for(int i = 0;i < n - 1;i++){
            s = countNum(s);
        }
        return s;
    }

    public static String countNum(String s) {
        StringBuffer str=new StringBuffer();
        for(int i=0;i<s.length();){
            char target=s.charAt(i);
            int num=1;
            while(++i<s.length()&&s.charAt(i)==target){
                num++;
            }
            str.append(num).append(target-'0');
        }
        return str.toString();
    }

    public static void main(String[] args) {
        System.out.println(countAndSay(4));
    }
}
